//
//  XYWelcomeVC.swift
//  SinaWB_XY
//
//  Created by 小熊猫 on 15/10/14.
//  Copyright © 2015年 小熊猫. All rights reserved.
//

import UIKit
import SDWebImage

class XYWelcomeVC: UIViewController {

    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        view.backgroundColor = UIColor.whiteColor()

        view.addSubview(headimageView)
        view.addSubview(welComeLabel)
    }

    
    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        
        headimageView.y = 200
        UIView.animateWithDuration(1, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 0, options: [ ], animations: { () -> Void in
            self.headimageView.y = 100
            }) { (finish) -> Void in
                self.welComeLabel.centerX = self.headimageView.centerX
                self.welComeLabel.y = CGRectGetMaxY(self.headimageView.frame) + 5
                
               UIView.animateWithDuration(2, animations: { () -> Void in
                self.welComeLabel.alpha = 1
                }, completion: { (finish) -> Void in
                    
                    //跳转
                    let window = UIApplication.sharedApplication().delegate!.window!
                    window?.rootViewController = XYTabBarController()
               })
        }
        
    }
    
    
//懒加载
    //图片
    private lazy var headimageView:UIImageView = {
        let imageView = UIImageView()
        imageView.size = CGSizeMake(90, 90)
        imageView.centerX = SCREENW * 0.5
        
        //切圆
        imageView.layer.borderColor = UIColor.blackColor().CGColor
        imageView.layer.borderWidth = 2
        imageView.layer.cornerRadius = imageView.height * 0.5
        imageView.layer.masksToBounds = true
        
        let url = NSURL(string: (XYWebModel.loadUserAccount()!.avatar_large)!)
        imageView.sd_setImageWithURL(url, placeholderImage: UIImage(named: "avatar_default_big"))
        
        return imageView
    }()
    
    //label
    private lazy var welComeLabel:UILabel = {
      
        let label = UILabel()
        label.text = "欢迎回来"
        
        label.textColor = UIColor.grayColor()
        label.sizeToFit()
        
        label.alpha = 0
        
        return label
        
    }()

}





